package user

import (
	"context"
	"go.uber.org/zap"
	"math/rand"
	"srv/config"
	"srv/internal/model/dao"
	__ "srv/proto"
	"time"
)

// 实现方法
func (s *UserService) UserSend(ctx context.Context, req *__.UserSendRequest) (resp *__.UserSendResponse, err error) {
	var user dao.User
	config.DB.Where("mobile=?", req.Mobile).Limit(1).Find(&user)
	if user.ID == 0 {
		zap.S().Error("该用户不存在")
		return
	}
	code := rand.Intn(9999)
	//_, err = tools.SendSms(req.Mobile, strconv.Itoa(code))
	//if err != nil {
	//	zap.S().Error("短信发送失败")
	//	return nil, err
	//}
	config.Rdb.Set(req.Mobile, code, time.Minute*4)
	zap.S().Info("短信发送成功")
	return nil, err
}
